package so.sao.shop.supplier.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import so.sao.shop.supplier.config.Constant;
import so.sao.shop.supplier.domain.User;
import so.sao.shop.supplier.pojo.Result;
import so.sao.shop.supplier.service.CheckingAccountRecordService;
import so.sao.shop.supplier.util.CheckUtil;
import so.sao.shop.supplier.util.JwtTokenUtil;
import so.sao.shop.supplier.util.Ognl;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>Version: supplier V1.2.0 </p>
 * <p>Title: CheckingAccountRecordController</p>
 * <p>Description: 对账记录</p>
 *
 * @author: fangzhou
 * @Date: Created in 2017/11/22 10:28
 */
@RestController
@RequestMapping("/checkingRecord")
public class CheckingAccountRecordController {

    @Autowired
    private CheckingAccountRecordService checkingAccountRecordService;

    @PostMapping(value = "/uploadAccountCheckingExcel")
    public Result importAccountCheckingExcel(HttpServletRequest request , @RequestPart("file") MultipartFile excelFile) throws Exception{
        //获取当前登录user
        User user = JwtTokenUtil.getCurrentUser();
        //判断是否登陆
        if (Ognl.isNull(user)) {
            return Result.fail(Constant.MessageConfig.MSG_USER_NOT_LOGIN);
        }
        String tempPath = request.getSession().getServletContext().getRealPath("") + "/file";// 文件上传到的文件夹
        //判断文件是否选择文件
        if (null == excelFile || excelFile.isEmpty()) {
            return Result.fail("文件为空,请选择文件");
        }
        return checkingAccountRecordService.uploadAccountCheckingExcel(excelFile, tempPath,user);

    }

}
